package study.ttl.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import study.ttl.entity.Category;
import study.ttl.mapper.CategoryMapper;
import study.ttl.service.CategoryService;
import study.ttl.service.LogService;


import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;



    /**
     * 添加分类
     * @param category
     */
    @Override
    public void add(Category category) {
        categoryMapper.insert(category);
    }

    /**
     * 根据id删除分类
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }


    /**
     * 修改分类信息
     * @param category
     */
    @Override
    public void update(Category category) {
        categoryMapper.updateById(category);
    }

    /**
     * 根据id查询分类
     * @param id
     * @return
     */
    @Override
    public Category selectById(Integer id) {
        Category category = categoryMapper.selectById(id);
        return category;
    }

    /**
     * 查询所有分类
     * @return
     */
    @Override
    public List<Category> selectAll(Category category) {
        List<Category> userList = categoryMapper.selectAll(category);
        return userList;
    }

    /**
     * 分页查询分类
     * @param pageNum
     * @param pageSize
     * @param category
     * @return
     */
    @Override
    public PageInfo<Category> selectPage(Integer pageNum, Integer pageSize, Category category) {
        PageHelper.startPage(pageNum, pageSize);
        List<Category> categoryList = categoryMapper.selectAll(category);
        return PageInfo.of(categoryList);
    }

    /**
     * 批量删除分类
     * @param ids
     */
    @Override
    public void deleteBatch(List<Integer> ids) {
        categoryMapper.deleteBatch(ids);
    }







}
